<template>
  <div class="TeachingVideos">
    <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
      <el-tab-pane
        v-for="(item, index) in tabsList"
        :key="index"
        :label="item.label"
        :name="index"
      >
      </el-tab-pane>
    </el-tabs>
    <Video
      v-if="activeTab.type === 'mp4' && activeTab.url"
      :url="activeTab.url"
    ></Video>
    <XnFilePreview
      v-if="activeTab.type !== 'mp4' && activeTab.url"
      :src="activeTab.url"
      :file-type="activeTab.type"
    />
  </div>
</template>

<script setup>
import { ref, h, onMounted } from "vue";
import Video from "../common/Video.vue";
import XnFilePreview from "../common/FilePreview.vue";
import { parseUrlFileType } from "../../utils/aes";
const tabsList = ref([
  { label: "案例导入语", name: "caseIntroduce" },
  { label: "案例视频", name: "caseVideo" },
  { label: "案例教学手册", name: "caseTeachingData" },
  { label: "案例正文", name: "caseText" },
]);
const activeTab = ref({});
const activeName = ref(0);

const handleClick = (tab, event) => {
  activeTab.value = {};
  activeName.value = tab.props.name;
  activeTab.value = tabsList.value[activeName.value];
};
// props
const props = defineProps({
  data: {
    type: Object,
    default: () => {},
  },
});

onMounted(() => {
  tabsList.value = tabsList.value.map((item) => {
    // 从路径里获取文件类型
    const urlDto = parseUrlFileType(props.data[item.name]);
    return { ...item, ...urlDto };
  });

  activeTab.value = tabsList.value?.[activeName.value];
});

watch(
  () => activeTab.value,
  (newVal) => {
    if (!newVal.url) {
      return;
    }
    if (newVal.type !== "mp4") {
      // previewRef.value.onOpen({
      //   downloadPath: newVal.url,
      //   suffix: newVal.type,
      // });
    }
  }
);
</script>

<style lang="less" scoped>
.TeachingVideos {
  // padding: 20px;
  .demo-tabs {
    :deep(.el-tabs__header) {
      .el-tabs__item {
        height: 40px;
        line-height: 40px;
        font-weight: bold;
        padding: 10px 20px;
      }
    }
    :deep(.el-tabs__content) {
      padding: 10px 0;
    }
    :deep(.el-tabs__nav-wrap::after) {
      height: 1px;
    }
    :deep(.el-tabs__item.is-active) {
      color: #217300;
    }
    :deep(.el-tabs__item:hover) {
      color: #217300;
    }
    :deep(.el-tabs__active-bar) {
      background-color: #217300;
    }
    :deep(.el-tabs__nav-wrap:after) {
      display: none;
    }
  }
}
</style>
